package cn.com.infohold.smartcity.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

import cn.com.infohold.smartcity.R;
import cn.com.infohold.smartcity.activity.Landinfo.LandInfoDetail_Activity;
import cn.com.infohold.smartcity.api.bean.LandInfoBean;
import cn.com.infohold.smartcity.parent.ParentActivity;

/**
 * Created by Monsoon on 2017/11/3.
 */
public class LandInfo_Adapter extends RecyclerView.Adapter<LandInfo_Adapter.mViewHolder> {

    Context context;
    List<LandInfoBean> mList;

    public LandInfo_Adapter(Context context, List<LandInfoBean> mList) {
        this.context = context;
        this.mList = mList;
    }

    @Override
    public mViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        mViewHolder viewHolder = new mViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_landinfo_manage, parent, false));
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(mViewHolder holder, int position) {

        LandInfoBean bean = mList.get(position);

        holder.tv_landid.setText(bean.getId());
        switch (bean.getStatus()){
            case "1":
                holder.tv_status.setText("保存");
                break;
            case "2":
                holder.tv_status.setText("提交一级审批");
                break;
            case "3":
                holder.tv_status.setText("一级审批未通过");
                break;
            case "4":
                holder.tv_status.setText("一级审批关闭");
                break;
            case "5":
                holder.tv_status.setText("待二级审批");
                break;
            case "6":
                holder.tv_status.setText("二级审批不通过");
                break;
            case "7":
                holder.tv_status.setText("二级审批关闭");
                break;
            case "8":
                holder.tv_status.setText("二级审批通过");
                break;
            default:
                break;
        }

        //holder.tv_landtype.setText(bean.getTypecodeid());
        holder.tv_area.setText(bean.getArea() + "㎡");
        holder.tv_easttill.setText("东至：" + bean.getEasttill());
        holder.tv_westtill.setText("西至：" + bean.getWesttill());
        holder.tv_northtill.setText("北至：" + bean.getNorthtill());
        holder.tv_southtill.setText("南至：" + bean.getSouthtill());

        holder.ll_item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context,LandInfoDetail_Activity.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable("land_detail",bean);
                intent.putExtra("land_bundle",bundle);
                context.startActivity(intent);
                ((ParentActivity)context).overridePendingTransitionFade();
            }
        });

    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class mViewHolder extends RecyclerView.ViewHolder {
        LinearLayout ll_item;
        TextView tv_landid;
        TextView tv_status;
        TextView tv_landtype;
        TextView tv_area;
        TextView tv_easttill;
        TextView tv_westtill;
        TextView tv_southtill;
        TextView tv_northtill;

        public mViewHolder(View itemView) {
            super(itemView);
            ll_item = (LinearLayout) itemView.findViewById(R.id.ll_item);
            tv_landid = (TextView) itemView.findViewById(R.id.tv_landid);
            tv_status = (TextView) itemView.findViewById(R.id.tv_status);
            tv_landtype = (TextView) itemView.findViewById(R.id.tv_landtype);
            tv_area = (TextView) itemView.findViewById(R.id.tv_area);
            tv_easttill = (TextView) itemView.findViewById(R.id.tv_easttill);
            tv_westtill = (TextView) itemView.findViewById(R.id.tv_westtill);
            tv_southtill = (TextView) itemView.findViewById(R.id.tv_southtill);
            tv_northtill = (TextView) itemView.findViewById(R.id.tv_northtill);
        }
    }
}
